package com.qys.livesMall.system.source.controller;


import com.qys.livesMall.common.result.R;
import com.qys.livesMall.framework.view.QysPage;
import com.qys.livesMall.system.source.domain.dto.dict.AddDictType;
import com.qys.livesMall.system.source.domain.dto.dict.DictTypeSearch;
import com.qys.livesMall.system.source.domain.dto.dict.EditDictType;
import com.qys.livesMall.system.source.domain.vo.dict.DictTypeVO;
import com.qys.livesMall.system.source.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据字典信息
 *
 * @author wanglei
 */
@RestController
@RequestMapping("/system/dict/type")
public class SysDictTypeController {
    @Autowired
    private ISysDictTypeService dictTypeService;

    /**
     * 字典类型列表
     * @param search
     * @return
     */
    @GetMapping("/list")
    public R<QysPage<DictTypeVO>> list(DictTypeSearch search) {
        return R.ok(dictTypeService.selectDictTypeList(search));
    }



    /**
     * 查询字典类型详细
     */
    @GetMapping(value = "/{dictId}")
    public R<DictTypeVO> getInfo(@PathVariable Long dictId) {
        return R.ok(dictTypeService.selectDictTypeById(dictId));
    }

    /**
     * 新增字典类型
     */
    @PostMapping
    public R add(@Validated @RequestBody AddDictType dict) {
        return dictTypeService.insertDictType(dict);
    }

    /**
     * 修改字典类型
     */
    @PutMapping
    public R edit(@Validated @RequestBody EditDictType dict) {
        return dictTypeService.updateDictType(dict);
    }

    /**
     * 删除字典类型
     */
    @DeleteMapping("/{dictIds}")
    public R remove(@PathVariable Long[] dictIds) {
        dictTypeService.deleteDictTypeByIds(dictIds);
        return R.ok();
    }

    /**
     * 刷新字典缓存
     */
    @DeleteMapping("/refreshCache")
    public R refreshCache() {
        dictTypeService.resetDictCache();
        return R.ok();
    }

    /**
     * 获取字典选择框列表
     */
    @GetMapping("/optionselect")
    public R<List<DictTypeVO>> optionselect() {
        List<DictTypeVO> dictTypes = dictTypeService.selectDictTypeAll();
        return R.ok(dictTypes);
    }
}
